/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package khmhappointmentsystem;

import java.awt.Frame;
import java.sql.Connection;
import java.util.HashMap;
import java.util.Map;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author mbelisle
 */
public class ReportFill
{

    public void generateReport(String reportLocation, Connection connection)
    {
        try
        {
            JasperPrint jasperPrint = JasperFillManager.fillReport(reportLocation, new HashMap(), connection); //Fill the report
            JasperViewer.viewReport(jasperPrint, false);
        }
        catch (JRException e)
        {
            e.printStackTrace();
        }


    }

    void generateReport(String reportLocation, Map parameters, Connection connection, java.lang.String reportTitle)
    {
        try
        {


            JasperPrint jasperPrint = JasperFillManager.fillReport(reportLocation, parameters, connection); //Fill the report
            JasperViewer.viewReport(jasperPrint, false);
            Frame[] viewer = JasperViewer.getFrames();
            for (int i = 0; i < viewer.length; i++)
            {
                if (viewer[i].getTitle().contains("Jasper"))
                {
                    viewer[i].setTitle("KHMH Appointment System - " + reportTitle);
                    viewer[i].setIconImage(new javax.swing.ImageIcon(getClass().getResource("resources/report.png")).getImage());
                }
            }
        }
        catch (JRException e)
        {
            e.printStackTrace();
        }
    }
}
